home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / c / cutils-1.0-l / cutils-1
Encoding:
Text File  |  1996-06-29  |  8.5 KB  |  322 lines

  1. diff -Nru cutils-std/lib/Makefile cutils/lib/Makefile
  2. --- cutils-std/lib/Makefile    Sat Jun 29 18:37:27 1996
  3. +++ cutils/lib/Makefile    Sat Jun 29 19:11:12 1996
  4. @@ -1,7 +1,7 @@
  5.  #    $Id: Makefile,v 1.12 1996/06/29 16:37:27 sandro Exp $
  6.  
  7.  LIB=    cutils
  8. -SRCS=    hash.c version.c pattern.c
  9. +SRCS=    hash.c version.c pattern.c err.c
  10.  
  11.  CFLAGS+=-I.
  12.  
  13. diff -Nru cutils-std/lib/err.c cutils/lib/err.c
  14. --- cutils-std/lib/err.c    Thu Jan  1 01:00:00 1970
  15. +++ cutils/lib/err.c    Sat Jun 29 19:11:12 1996
  16. @@ -0,0 +1,216 @@
  17. +/*-
  18. + * Copyright (c) 1993
  19. + *    The Regents of the University of California.  All rights reserved.
  20. + *
  21. + * Redistribution and use in source and binary forms, with or without
  22. + * modification, are permitted provided that the following conditions
  23. + * are met:
  24. + * 1. Redistributions of source code must retain the above copyright
  25. + *    notice, this list of conditions and the following disclaimer.
  26. + * 2. Redistributions in binary form must reproduce the above copyright
  27. + *    notice, this list of conditions and the following disclaimer in the
  28. + *    documentation and/or other materials provided with the distribution.
  29. + * 3. All advertising materials mentioning features or use of this software
  30. + *    must display the following acknowledgement:
  31. + *    This product includes software developed by the University of
  32. + *    California, Berkeley and its contributors.
  33. + * 4. Neither the name of the University nor the names of its contributors
  34. + *    may be used to endorse or promote products derived from this software
  35. + *    without specific prior written permission.
  36. + *
  37. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  38. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  39. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  41. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  42. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  43. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  44. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  45. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  46. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. + * SUCH DAMAGE.
  48. + */
  49. +
  50. +#if defined(LIBC_SCCS) && !defined(lint)
  51. +static char sccsid[] = "@(#)err.c    8.1 (Berkeley) 6/4/93";
  52. +#endif /* LIBC_SCCS and not lint */
  53. +
  54. +#include <err.h>
  55. +#include <errno.h>
  56. +#include <stdio.h>
  57. +#include <stdlib.h>
  58. +#include <string.h>
  59. +
  60. +#ifdef __STDC__
  61. +#include <stdarg.h>
  62. +#else
  63. +#include <varargs.h>
  64. +#endif
  65. +
  66. +extern char *__progname;        /* Program name, from crt0. */
  67. +
  68. +static FILE *err_file; /* file to use for error output */
  69. +static void (*err_exit)(int);
  70. +
  71. +void
  72. +err_set_file(void *fp)
  73. +{
  74. +    if (fp)
  75. +        err_file = fp;
  76. +    else
  77. +        err_file = stderr;
  78. +}
  79. +
  80. +void
  81. +err_set_exit(void (*ef)(int))
  82. +{
  83. +    err_exit = ef;
  84. +}
  85. +
  86. +__dead void
  87. +#ifdef __STDC__
  88. +err(int eval, const char *fmt, ...)
  89. +#else
  90. +err(eval, fmt, va_alist)
  91. +    int eval;
  92. +    const char *fmt;
  93. +    va_dcl
  94. +#endif
  95. +{
  96. +    va_list ap;
  97. +#if __STDC__
  98. +    va_start(ap, fmt);
  99. +#else
  100. +    va_start(ap);
  101. +#endif
  102. +    verr(eval, fmt, ap);
  103. +    va_end(ap);
  104. +}
  105. +
  106. +__dead void
  107. +verr(eval, fmt, ap)
  108. +    int eval;
  109. +    const char *fmt;
  110. +    va_list ap;
  111. +{
  112. +    int sverrno;
  113. +
  114. +    sverrno = errno;
  115. +    if (! err_file)
  116. +        err_set_file((FILE *)0);
  117. +    (void)fprintf(err_file, "%s: ", __progname);
  118. +    if (fmt != NULL) {
  119. +        (void)vfprintf(err_file, fmt, ap);
  120. +        (void)fprintf(err_file, ": ");
  121. +    }
  122. +    (void)fprintf(err_file, "%s\n", strerror(sverrno));
  123. +    if(err_exit)
  124. +        err_exit(eval);
  125. +    exit(eval);
  126. +}
  127. +
  128. +__dead void
  129. +#if __STDC__
  130. +errx(int eval, const char *fmt, ...)
  131. +#else
  132. +errx(eval, fmt, va_alist)
  133. +    int eval;
  134. +    const char *fmt;
  135. +    va_dcl
  136. +#endif
  137. +{
  138. +    va_list ap;
  139. +#if __STDC__
  140. +    va_start(ap, fmt);
  141. +#else
  142. +    va_start(ap);
  143. +#endif
  144. +    verrx(eval, fmt, ap);
  145. +    va_end(ap);
  146. +}
  147. +
  148. +__dead void
  149. +verrx(eval, fmt, ap)
  150. +    int eval;
  151. +    const char *fmt;
  152. +    va_list ap;
  153. +{
  154. +    if (! err_file)
  155. +        err_set_file((FILE *)0);
  156. +    (void)fprintf(err_file, "%s: ", __progname);
  157. +    if (fmt != NULL)
  158. +        (void)vfprintf(err_file, fmt, ap);
  159. +    (void)fprintf(err_file, "\n");
  160. +    if (err_exit)
  161. +        err_exit(eval);
  162. +    exit(eval);
  163. +}
  164. +
  165. +void
  166. +#if __STDC__
  167. +warn(const char *fmt, ...)
  168. +#else
  169. +warn(fmt, va_alist)
  170. +    const char *fmt;
  171. +    va_dcl
  172. +#endif
  173. +{
  174. +    va_list ap;
  175. +#if __STDC__
  176. +    va_start(ap, fmt);
  177. +#else
  178. +    va_start(ap);
  179. +#endif
  180. +    vwarn(fmt, ap);
  181. +    va_end(ap);
  182. +}
  183. +
  184. +void
  185. +vwarn(fmt, ap)
  186. +    const char *fmt;
  187. +    va_list ap;
  188. +{
  189. +    int sverrno;
  190. +
  191. +    sverrno = errno;
  192. +    if (! err_file)
  193. +        err_set_file((FILE *)0);
  194. +    (void)fprintf(err_file, "%s: ", __progname);
  195. +    if (fmt != NULL) {
  196. +        (void)vfprintf(err_file, fmt, ap);
  197. +        (void)fprintf(err_file, ": ");
  198. +    }
  199. +    (void)fprintf(err_file, "%s\n", strerror(sverrno));
  200. +}
  201. +
  202. +void
  203. +#ifdef __STDC__
  204. +warnx(const char *fmt, ...)
  205. +#else
  206. +warnx(fmt, va_alist)
  207. +    const char *fmt;
  208. +    va_dcl
  209. +#endif
  210. +{
  211. +    va_list ap;
  212. +#ifdef __STDC__
  213. +    va_start(ap, fmt);
  214. +#else
  215. +    va_start(ap);
  216. +#endif
  217. +    vwarnx(fmt, ap);
  218. +    va_end(ap);
  219. +}
  220. +
  221. +void
  222. +vwarnx(fmt, ap)
  223. +    const char *fmt;
  224. +    va_list ap;
  225. +{
  226. +    if (! err_file)
  227. +        err_set_file((FILE *)0);
  228. +    (void)fprintf(err_file, "%s: ", __progname);
  229. +    if (fmt != NULL)
  230. +        (void)vfprintf(err_file, fmt, ap);
  231. +    (void)fprintf(err_file, "\n");
  232. +}
  233. diff -Nru cutils-std/lib/err.h cutils/lib/err.h
  234. --- cutils-std/lib/err.h    Thu Jan  1 01:00:00 1970
  235. +++ cutils/lib/err.h    Sat Jun 29 19:11:12 1996
  236. @@ -0,0 +1,85 @@
  237. +/*-
  238. + * Copyright (c) 1993
  239. + *    The Regents of the University of California.  All rights reserved.
  240. + *
  241. + * Redistribution and use in source and binary forms, with or without
  242. + * modification, are permitted provided that the following conditions
  243. + * are met:
  244. + * 1. Redistributions of source code must retain the above copyright
  245. + *    notice, this list of conditions and the following disclaimer.
  246. + * 2. Redistributions in binary form must reproduce the above copyright
  247. + *    notice, this list of conditions and the following disclaimer in the
  248. + *    documentation and/or other materials provided with the distribution.
  249. + * 3. All advertising materials mentioning features or use of this software
  250. + *    must display the following acknowledgement:
  251. + *    This product includes software developed by the University of
  252. + *    California, Berkeley and its contributors.
  253. + * 4. Neither the name of the University nor the names of its contributors
  254. + *    may be used to endorse or promote products derived from this software
  255. + *    without specific prior written permission.
  256. + *
  257. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  258. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  259. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  260. + * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  261. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  262. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  263. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  264. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  265. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  266. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  267. + * SUCH DAMAGE.
  268. + *
  269. + *    @(#)err.h    8.1 (Berkeley) 6/2/93
  270. + */
  271. +
  272. +#ifndef _ERR_H_
  273. +#define    _ERR_H_
  274. +
  275. +/*
  276. + * Don't use va_list in the err/warn prototypes.   Va_list is typedef'd in two
  277. + * places (<machine/varargs.h> and <machine/stdarg.h>), so if we include one
  278. + * of them here we may collide with the utility's includes.  It's unreasonable
  279. + * for utilities to have to include one of them to include err.h, so we get
  280. + * _BSD_VA_LIST_ from <machine/ansi.h> and use it.
  281. + */
  282. +
  283. +#if 0
  284. +#include <machine/ansi.h>
  285. +#include <sys/cdefs.h>
  286. +#endif
  287. +
  288. +#include <stdarg.h>
  289. +
  290. +#ifndef __dead
  291. +#define __dead
  292. +#define __dead2
  293. +#endif
  294. +
  295. +#ifndef __P
  296. +#define __P(p) p
  297. +#endif
  298. +
  299. +#ifndef _BSD_VA_LIST_
  300. +#define _BSD_VA_LIST_ va_list
  301. +#endif
  302. +
  303. +#ifndef __BEGIN_DECLS
  304. +#define __BEGIN_DECLS
  305. +#define __END_DECLS
  306. +#endif
  307. +
  308. +__BEGIN_DECLS
  309. +__dead void    err __P((int, const char *, ...)) __dead2;
  310. +__dead void    verr __P((int, const char *, _BSD_VA_LIST_)) __dead2;
  311. +__dead void    errx __P((int, const char *, ...)) __dead2;
  312. +__dead void    verrx __P((int, const char *, _BSD_VA_LIST_)) __dead2;
  313. +void        warn __P((const char *, ...));
  314. +void        vwarn __P((const char *, _BSD_VA_LIST_));
  315. +void        warnx __P((const char *, ...));
  316. +void        vwarnx __P((const char *, _BSD_VA_LIST_));
  317. +void        err_set_file __P((void *));
  318. +void        err_set_exit __P((void (*)__P((int))));
  319. +__END_DECLS
  320. +
  321. +#endif /* !_ERR_H_ */
  322.